#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QVBoxLayout>
#include<QHBoxLayout>
#include<QGridLayout>
#include<QFormLayout>
#include<QLabel>
#include<QLineEdit>
#include<QCheckBox>
#include<QSpacerItem>
#include<QPushButton>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QGridLayout *gridLayout = new QGridLayout(this);
    QHBoxLayout *hLayout = new QHBoxLayout(this);
    QVBoxLayout *vLayout = new QVBoxLayout(this);
    QFormLayout *formLayout = new QFormLayout(this);

    QLabel *label1 = new QLabel();
    label1->setText("个人信息");
    QFont font("Microsoft YaHei",10,50);

    QLineEdit *name = new QLineEdit();
    QLineEdit *sex = new QLineEdit();
    QLineEdit *age = new QLineEdit();
    QLineEdit *phone = new QLineEdit();
    QLineEdit *address = new QLineEdit();

    formLayout->addRow("姓名",name);
    formLayout->addRow("性别",sex);
    formLayout->addRow("年龄",age);
    formLayout->addRow("电话",phone);
    formLayout->addRow("地址",address);
    formLayout->setSpacing(20);
    formLayout->setContentsMargins(10,10,40,30);

    QLabel *label2 = new QLabel();
    label2->setText("测量参数");
    label2->setFont(font);

    QCheckBox *temp = new QCheckBox();
    QCheckBox *nibp = new QCheckBox();
    QCheckBox *acg = new QCheckBox();
    QCheckBox *resp = new QCheckBox();
    QCheckBox *spo2 = new QCheckBox();

    temp->setText("体温");
    nibp->setText("血压");
    acg->setText("心电");
    resp->setText("呼吸");
    spo2->setText("血氧");

    vLayout->addWidget(temp);
    vLayout->addWidget(nibp);
    vLayout->addWidget(acg);
    vLayout->addWidget(resp);
    vLayout->addWidget(spo2);
    vLayout->setSpacing(20);
    vLayout->setContentsMargins(10,10,20,30);

    QSpacerItem *verticalSpacer = new QSpacerItem(40,20,QSizePolicy::Expanding,QSizePolicy::Expanding);
    QPushButton *okBtn = new QPushButton();
    QPushButton *cancelBtn = new QPushButton;

    okBtn->setText("确定");
    cancelBtn->setText("取消");

    hLayout->addWidget(okBtn);
    hLayout->addWidget(cancelBtn);

    gridLayout->addWidget(label1,0,0,1,1);
    gridLayout->addWidget(label2,0,1,1,1);
    gridLayout->addLayout(formLayout,1,0,5,1);
    gridLayout->addLayout(vLayout,1,1,5,1);
    gridLayout->addItem(verticalSpacer,6,0,1,2);
    gridLayout->addLayout(hLayout,7,0,1,2);

    setWindowTitle("LayoutTest");


    //invalid
    //setLayout(gridLayout);


//    this->window()->setLayout(gridLayout);

    //OK
//    auto n = new QWidget(this);
//    n->setLayout(gridLayout);
//    this->setCentralWidget(n);


    //error
//    delete layout();
//    setLayout(gridLayout);

    auto cw = takeCentralWidget();
    delete cw;

    auto n = new QWidget(this);
    n->setLayout(gridLayout);
    this->setCentralWidget(n);




}

MainWindow::~MainWindow()
{
    delete ui;
}

